import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

public class C10K {

    public static void main(String[] args) throws Exception {
        InetSocketAddress socket = new InetSocketAddress(args[0], Integer.parseInt(args[1]));

        for (int port = 10000; port < 60001; port++) {
            SocketChannel channel = SocketChannel.open();
            channel.bind(new InetSocketAddress("192.168.110.11", port));
            channel.connect(socket);
            channel.configureBlocking(false);

            String message = "port:" + port + "\n";
            ByteBuffer byteBuffer = ByteBuffer.allocateDirect(message.toCharArray().length);
            sendMessage(channel, byteBuffer, message);
        }

        try {
            System.in.read();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static void sendMessage(SocketChannel channel, ByteBuffer byteBuffer, String message) {
        try {
            byteBuffer.clear();
            byteBuffer.put(message.getBytes());
            byteBuffer.rewind();

            channel.write(byteBuffer);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
